<?php
namespace Admin\Controller;
use User\Api\UserApi;

class AttrController extends AdminController {
    public function index(){
        $nickname       =   I('nickname');
        $map['status']  =   array('egt',0);
        if(is_numeric($nickname)){
            $map['id|title']=   array(intval($nickname),array('like','%'.$nickname.'%'),'_multi'=>true);
        }else{
            $map['title']    =   array('like', '%'.(string)$nickname.'%');
        }

        $list   = $this->lists('Attr',$map,'id');
        int_to_string($list);
        $this->assign('_list', $list);
        $this->meta_title = '新增商品属性';
        $this->display();
    }


    public function add($id=0,$title=0){
        if(IS_POST){            
            $Attr = D("attr");
            $res = $Attr->create(I("post."));
            if($res){
                if($Attr->add($res)){
                    $this->success('添加成功',U('index'));
                }else{
                    $this->error('添加失败');
                }
            }else{
                $this->error(D("attr")->getError());
            }
        }else{
            $this->assign('sid',$id);
            $this->assign('title',$title);
            $this->display();
        }
    }

    public function del(){
        $id = I('get.id');
        $res = D('Attr')->where(array('id'=>$id))->delete();
        if($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }


}